package com.lhoverc.controller.admin;

import com.lhoverc.pojo.PageBean;
import com.lhoverc.pojo.Result;
import com.lhoverc.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-12
 * @Description:
 * @Version: 1.0
 */

@Slf4j
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {
    @Autowired
    private UserService userService;

    /**
     * 分页查询用户信息
     *
     * @param page
     * @param pageSize
     * @param username
     * @param address
     * @param status
     * @return
     */
    @GetMapping("/GetAllUsers")
    public Result page(String username,
                       String address,
                       Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询，参数:{},{},{},{},{}", page, pageSize, username, address, status);

        PageBean pageBean = userService.page(page, pageSize, username, address, status);

        return Result.success(pageBean);
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @GetMapping("/deleteUser/{id}")
    public Result deleteUser(@PathVariable Integer id) {
        userService.deleteUser(id);
        return Result.success();
    }

    /**
     * 获取用户总数
     * @return
     */
    @GetMapping("/getUserNum")
    public Result getUserNum(){
        Integer num = userService.getUserNum();
        return Result.success(num);
    }
}
